package cn.sdhuijin.vms.service;

import java.util.List;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import cn.sdhuijin.vms.dao.IPersonDao;
import cn.sdhuijin.vms.model.CardType;
import cn.sdhuijin.vms.model.Person;

@Service
public class PersonService implements IPersonService {
	final Logger logger = LoggerFactory.getLogger(PersonService.class);
	@Inject
	private IPersonDao personDao;

	@Override
	public void save(Person person) {
		person.getCard().setType(CardType.PERSON);
		personDao.save(person);
	}

	@Override
	public void delete(Long personId) {
		personDao.delete(personId);
		;
	}

	@Override
	public Page<Person> getList(Integer page, Integer rows) {
		return personDao.findAll(new PageRequest(page, rows));
	}

	@Override
	public Person load(Long personId) {
		return personDao.findOne(personId);
	}

	@Override
	public Page<Person> getListByOrgIds(List<Long> orgIds, Integer page,
			Integer rows) {
		return personDao.findByOrganizationIdIn(orgIds, new PageRequest(page,
				rows));
	}

}
